package org.fqh.service.impl;

import org.fqh.dao.UserDao;
import org.fqh.entity.TUser;
import org.fqh.service.UserService;
import org.fqh.utils.EncryptUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
* @author fqh 
* @version 创建时间：2018年3月20日 上午10:54:16
* 类说明
*/
@Service
public class UserServiceImpl implements UserService {
	
	@Autowired
	UserDao userDao;
	
	
	@Override
	public void updateTUser(TUser user)  throws Exception{
		userDao.updateTUser(user);

	}

	@Override
	public void deleteTUser(int id)  throws Exception{
		userDao.deleteTUser(id);

	}

	@Override
	public int createTUser(TUser user)  throws Exception{
		user.setPassword(EncryptUtils.md5Password(user.getPassword()));
		return userDao.createTUser(user);
	}

	@Override
	public TUser getById(int id)  throws Exception{ 
		return userDao.getById(id);
	}
	@Override
	public TUser CheckUserNamePassword(TUser user)  throws Exception{
		TUser dbuser = userDao.getUserByName(user.getUsername());
		String password =EncryptUtils.md5Password(user.getPassword());
		if(dbuser==null||!password.equals(dbuser.getPassword())) {
			return null;
		}else {
			return dbuser; 	
		}
		
		
	}
}
